package system.security.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import system.security.dao.CommonResourceDao;
import system.security.entity.CommonResource;
import system.security.service.CommonResourceService;


@Transactional
@Service("commonResourceService")
public class CommonResourceServiceImpl implements CommonResourceService {

	@Autowired
	private CommonResourceDao commonResourceDao;
	
	@Transactional(readOnly=true)
	@Override
	public CommonResource getById(int commonResourceId) {
		CommonResource commonResource = commonResourceDao.get(commonResourceId);
		return commonResource;
	}

	@Override
	public CommonResource findByName(String commonResourcename) {
			List<CommonResource> list = commonResourceDao.findByProperty("commonResourcename", commonResourcename);
			if(!list.isEmpty()){
				return list.get(0);
			}
			return null;		
	}

	@Override
	@Transactional(readOnly = true)
	public List<CommonResource> getAll() {
		return commonResourceDao.list();
	}
	
	@Override
	public void save(CommonResource commonResource) throws Exception {
			commonResourceDao.saveOrUpdate(commonResource);
	}

	@Override
	public void delete(int commonResourceId) {
		commonResourceDao.remove(commonResourceId);
	}
	
	@Override
	public void delete(CommonResource commonResource){
		commonResourceDao.remove(commonResource);		
	}
	
}
